package cn.stylefeng.guns.modular.tool.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.tool.entity.ToolExpressReconciliationStInstall;
import cn.stylefeng.guns.modular.tool.mapper.ToolExpressReconciliationStInstallMapper;
import cn.stylefeng.guns.modular.tool.model.params.ToolExpressReconciliationStInstallParam;
import cn.stylefeng.guns.modular.tool.model.result.ToolExpressReconciliationStInstallResult;
import  cn.stylefeng.guns.modular.tool.service.ToolExpressReconciliationStInstallService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 申通报价设置 服务实现类
 * </p>
 *
 * @author zhucx
 * @since 2023-02-01
 */
@Service
public class ToolExpressReconciliationStInstallServiceImpl extends ServiceImpl<ToolExpressReconciliationStInstallMapper, ToolExpressReconciliationStInstall> implements ToolExpressReconciliationStInstallService {

    @Override
    public void add(ToolExpressReconciliationStInstallParam param){
        ToolExpressReconciliationStInstall entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(ToolExpressReconciliationStInstallParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(ToolExpressReconciliationStInstallParam param){
        ToolExpressReconciliationStInstall oldEntity = getOldEntity(param);
        ToolExpressReconciliationStInstall newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ToolExpressReconciliationStInstallResult findBySpec(ToolExpressReconciliationStInstallParam param){
        return null;
    }

    @Override
    public List<ToolExpressReconciliationStInstallResult> findListBySpec(ToolExpressReconciliationStInstallParam param,Long operateId){
        return this.baseMapper.findListBySpec(param,operateId);
    }

    @Override
    public LayuiPageInfo findPageBySpec(ToolExpressReconciliationStInstallParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(ToolExpressReconciliationStInstallParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private ToolExpressReconciliationStInstall getOldEntity(ToolExpressReconciliationStInstallParam param) {
        return this.getById(getKey(param));
    }

    private ToolExpressReconciliationStInstall getEntity(ToolExpressReconciliationStInstallParam param) {
        ToolExpressReconciliationStInstall entity = new ToolExpressReconciliationStInstall();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
